<template>
	<view>
		<view class="flex-column p-30" style="gap: 30rpx;" v-if="!noData">
			<view class="card p-30 flex-row align-center justify-between" v-for="(item,index) in list" :key="index">
				<view class="">
					<view class="fw-700 w-full">
						{{item.remark}}
					</view>
					<view class="small-size">
						{{$u.timeFormat(item.createtime, 'yyyy年mm月dd日')}}
					</view>
				</view>
				<view class="price-color">
					{{item.money}}
				</view>
			</view>
			<u-loadmore marginTop="120rpx" :status="status" />
		</view>
		<template v-else>
			<u-empty marginTop="240rpx" mode="data" icon="/static/common/img/no-data.png">
			</u-empty>
		</template>
	</view>
</template>

<script>
	import {
		withdrawProfitList
	} from '@/common/api.js'
	import {
		mapState
	} from "vuex";
	import commonMixin from '@/mixins/common.js';
	export default {
		mixins: [commonMixin],
		data() {
			return {
				status: 'loading',
				list: [],
				noData: false,
				page: 1,
				total: 0,
			}
		},
		computed: {
			...mapState([]),
		},
		onLoad() {
			// this.init()
		},
		methods: {
			init() {
				this.status = "loading";
				this.list = [];
				this.page = 1;
				this.noData = false;
				this.getList();
			},
			getList() {
				let vm = this;
				let params = {
					'page': this.page,
					'limit': this.$u.config.limit,
				};
				withdrawProfitList({
					params
				}).then(res => {
					if (res.rows.length != 0) {
						this.noData = false;
						this.list = this.list.concat(res.rows);
						this.total = res.total;
						this.page++;
						this.status = vm.page > Math.ceil(vm.total / vm.$u.config.limit) ? 'nomore' : "loadmore"
					} else {
						this.noData = true;
						this.status = "nomore"
					}
				}).catch(err => {
					vm.$refs.uToast.show({
						type: 'error',
						message: err.message,
						complete() {
							vm.loading = false;
						}
					})
				})
			},

			//上拉
			onPullDownRefresh() {
				this.status = "loading"
				this.init();
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 500);
			},
			//下拉
			onReachBottom() {
				let vm = this;
				this.status = 'loading';
				//延时为了看效果
				setTimeout(() => {
					if (vm.page > Math.ceil(vm.total / this.$u.config.limit)) {
						this.status = 'nomore';
					} else {
						vm.getList();
					}
				}, 200)
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>